Reverse String

Write a function that takes a string as input and returns the string reversed.

题目大意:翻转一个字符串

题目难度:Easy

/**
 * Created by gzdaijie on 16/5/5
 */
public class Solution {
    public String reverseString(String s) {
        if (s == null) return null;
        char arr[] = s.toCharArray();
        int mid = arr.length/2;
        for (int i = 0; i < mid; i++) {
            char ch = arr[i];
            arr[i] = arr[arr.length - i - 1];
            arr[arr.length - i - 1] = ch;
        }
        return String.valueOf(arr);
    }
}
gzdaijie            updated 2016-05-05 21:08:22

results matching ""

    No results matching ""